﻿@namespace AIShell.Pages.Session
@using Domain.Domain.Model.Enum
@using AIShell.Domain.Repositories
@page "/session/list"


<PageContainer Title="会话列表">
    <Content>
        <div style="text-align: center;">
            <Search Placeholder="输入回车"
                    EnterButton="@("搜索")"
                    Style="max-width: 522px; width: 100%;"
                    OnSearch="Search" />
        </div>
    </Content>
    <ChildContent>
        <div class="cardList">
            <AntList TItem="Sessions"
                     DataSource="_data"
                     ItemLayout="ListItemLayout.Horizontal"
                     Grid="LayoutModel._listGridType">
                <ListItem NoFlex>
                    @if (string.IsNullOrEmpty(context.Id))
                    {
                        <Button Type="dashed" class="newButton" @onclick="NavigateToAddSession">
                            <Icon Type="plus" Theme="outline" /> 创建会话
                        </Button>
                    }
                    else
                    {
                        <Card Hoverable Bordered Class="card" Actions="@(new[] {
                            connect(()=> Connect(context.Id)),
                            update(()=> Update(context.Id)) ,                        
                            delete(async ()=>await Delete(context.Id)) ,

                             })" Style="max-height:247px;">
                            <CardMeta>
                                <AvatarTemplate>
                                    <Icon Type="windows" Theme="outline" />
                                </AvatarTemplate>
                                <TitleTemplate>
                                    <a>@context.Name</a>
                                </TitleTemplate>
                                <DescriptionTemplate>
                                    <Tag Color="@PresetColor.Volcano.ToString()">@context.Host</Tag>
                                </DescriptionTemplate>
                            </CardMeta>
                        </Card>
                    }
                </ListItem>
            </AntList>
        </div>
    </ChildContent>
</PageContainer>

<style>
    .ant-typography {
        overflow: hidden; /* 防止内容溢出 */
        text-overflow: ellipsis; /* 超出部分显示省略号 */
        white-space: nowrap; /* 防止内容换行 */
    }

    .ant-tag {
        margin-top: 8px;
    }

    div.ant-typography, .ant-typography p {
        margin-bottom: 0;
    }
</style>

@code {
    RenderFragment connect(Action clickAction) =>@<a key="connect" @onclick="@clickAction">连接</a>;
    RenderFragment update(Action clickAction) =>@<a key="info" @onclick="@clickAction">修改</a>;
    RenderFragment delete(Action clickAction) => @<a key="delete" @onclick="@clickAction">删除</a> ;
}
